from Tank import Hitbox
from tkinter import Tk, Canvas,Label

tk = Tk()
tk.title("Tank 2024")
width=1000
height=800
canv = Canvas(tk, width=width, height=height, bg="alice blue")
canv.pack()



hb1 = Hitbox(0, 0, 100, 100)

hb3 = Hitbox(900, 700, 100, 100)

hr1 = canv.create_rectangle(hb1.get_left(), hb1.get_top(), hb1.get_right(), hb1.get_niz(), fill="green")

hr3 = canv.create_rectangle(hb3.get_left(), hb3.get_top(), hb3.get_right(), hb3.get_niz(), fill="red")




def on_key_press(event):
    if event.keycode == 27:
        exit()


    move_up(event)
    move_down(event)
    move_left(event)
    move_right(event)
    move_up1(event)
    move_down1(event)
    move_left1(event)
    move_right1(event)
y11=0
def move_down(event):
    global h
    global y11
    if event.keycode == 83 and y11>0:

        h+=1
        y11-=25
        canv.move(hr3, 0, 25)
        print("move down,Y11",y11)
def move_up(event):
    global h
    global y11
    if event.keycode == 87 and y11<height-100:
        y11+=25
        canv.move(hr3, 0,-25)
        print("move up,Y11",h,y11)

h=0
x11=0

def move_left(event):
    global h
    global x11
    if event.keycode == 65 and x11>-width +100:
        h += 1
        x11 -= 25
        canv.move(hr3,-25,0)
        print("move left,X11", x11)

def move_right(event):
    global h
    global x11
    if event.keycode ==68 and x11 <0:
        h+=1
        x11+= 25
        canv.move(hr3, 25, 0)
        print("move right,X11",x11)

y1=0
def move_down1(event):
    global h1
    global y1
    if event.keycode == 40 and y1 > -height+100:

        h1+=1
        y1-=25
        canv.move(hr1, 0, 25)
        print("move down,Y1",y1)

def move_up1(event):
    global h1
    global y1
    if event.keycode == 38 and y1<0:
        y1+=25
        canv.move(hr1, 0,-25)
        print("move up,Y1",h1,y1)

h1=0
x1=0
popa=0
def move_left1(event):
    global h1
    global x1
    if event.keycode == 37 and  x1>0:
        h1 += 1
        x1 -= 25
        canv.move(hr1,-25,0)
        print("move left,X1", x1)

def move_right1(event):
    global h1
    global x1
    global popa
    global lab
    if event.keycode ==39 and x1 < width -100:
        h1+=1
        x1+= 25
        canv.move(hr1, 25, 0)
        print("move right,X1",x1)


    if y11 == y1 + 700 and x11==x1-900\
    or y11==x1-900 and  y11 == y1 + 700:
        canv.itemconfig(hr3, fill='blue')
        popa += 1
        lab = Label(tk, text=f'ЗЕЛЕНЫЙ ПОЙМАН {popa} РАЗ',padx=20,pady=20)
        lab.pack()

    else:
        canv.itemconfig(hr3,fill='red')




tk.bind('<KeyPress>', on_key_press)
tk.mainloop()
